/**
 * ====================================================================
 * 问题列表
 * ====================================================================
 */
function Page() {
  this._init();
};

/**
 * 获取服务器数据
 * @param page 分页
 */
Page.prototype.fetchData = function (page, callback) {
  var self = this;
  $.ajax({
    url: io.question_list.content,
    type: 'post',
    data: {page: page},
    async: false,
    dataType: 'json',
    beforeSend: function () {

    },
    success: function (data) {
      data.resultCode <= 1000 ? callback(data) : console.log(data.message);
    },
    error: function () {
      console.log('请求超时：' + io.question_list.content);
    }
  });
};

// 渲染到页面
Page.prototype.renderData = function () {
  var self = this;
  var vue = new Vue({
    el: 'body',
    data: {
      page: 1,
      problemList: []
    },
    methods: {
      addProblemList: function () {
        var _this = this;
        self.fetchData(this.page, function (data) {
          _this.page++;
          data.problemList.forEach(ele => _this.problemList.push(ele));
        });
      }
    }
  });
  vue.addProblemList();
};

Page.prototype._init = function () {
  this.renderData();
};

module.exports = Page;